"use strict";
exports.__esModule = true;
var reducer1 = function (state, action) {
    return state;
};
console.log(reducer1(0, null));
// 修改state中的数据
var INCREMENT = 'INCREMENT';
var DECREMENT = 'DECREMENT';
var reducer2 = function (state, action) {
    if (action.type === INCREMENT) {
        return state + 1;
    }
    if (action.type === DECREMENT) {
        return state - 1;
    }
};
var action1 = { type: 'INCREMENT' };
var action2 = { type: 'DECREMENT' };
console.log(reducer2(0, action1));
console.log(reducer2(0, action2));
// reducer的switch版本
var reducer3 = function (state, action) {
    switch (action.type) {
        case INCREMENT:
            return state + 1;
        case DECREMENT:
            return state - 1;
        default:
            return state;
    }
};
console.log(reducer3(100, action1));
console.log(reducer3(100, action2));
// 应用的变化通常无法通过单一变量来反映，所以需要借助action中的第二个参数payload来做补充
var reducer4 = function (state, action) {
    switch (action.type) {
        case INCREMENT:
            return state + action.payload;
        case DECREMENT:
            return state - action.payload;
        default:
            return state;
    }
};
// 借助Action中的payload字段来补充increment/decrement中的“步长”
var action3 = { type: 'INCREMENT', payload: 100 };
var action4 = { type: 'DECREMENT', payload: 100 };
console.log(reducer4(0, action3));
console.log(reducer4(0, action4));
